package com.gxa.meiye.admin.platform.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gxa.meiye.admin.platform.pojo.vo.PermVo;
import com.gxa.meiye.admin.platform.pojo.vo.RoleVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;


@Component
public interface RoleMapper extends BaseMapper<RoleVo>{

    @Select("SELECT id,name,pid FROM t_web_menu WHERE pow IS NULL")
    List<PermVo> selectPerm();

    @Select("SELECT id,name FROM t_web_menu \n" +
            "WHERE pid = #{id} AND pow IS NOT NULL")
    List<Map<String,Object>> selectHandle(Integer id);

    @Select("SELECT id,name FROM t_web_menu \n" +
            "WHERE pow = 1  AND id IN (\n" +
            "\tSELECT menu_id\n" +
            "\tFROM t_web_role_menu\n" +
            "\tWHERE role_id = #{id}\n" +
            ")")
    List<PermVo> selectPermByUid(Integer id);

    @Delete("DELETE FROM t_web_role_menu WHERE role_id = #{rid} AND menu_id IN (\n" +
            " SELECT id FROM t_web_menu WHERE pow IS NOT NULL)")
    void delRoleMenu(Integer rid);

    @Insert("INSERT INTO `t_web_role_menu`(`role_id`, `menu_id`) VALUES (#{rid}, #{mid})")
    Integer addRoleMenu(Integer rid, Integer mid);
}
